package com.deer.wms.system.manage.web;

import com.deer.wms.intercept.annotation.Authority;
import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.CommonCode;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.system.manage.model.coderule.CodeRule;
import com.deer.wms.system.manage.service.CodeRuleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author : wei
 * @since : 2021-10-28 13:29:34
 **/
@RestController
@RequestMapping("/code/rule")
public class CodeRuleController {
    @Autowired
    private CodeRuleService codeRuleService;

    @ApiOperation(value = "新增编码规则")
    @Authority
    @ApiImplicitParams({@ApiImplicitParam(name = "access-token", value = "token", paramType = "header", dataType = "String", dataTypeClass = String.class, required = true)})
    @PostMapping("/insert")
    public Result add(@RequestBody CodeRule codeRule, @ApiIgnore @User CurrentUser currentUser) {
        if (currentUser == null) {
            return ResultGenerator.genFailResult(CommonCode.MISSING_PERMISSION_PARAMTER, null);
        }
        codeRuleService.createCodeRule(codeRule, currentUser);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        codeRuleService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody CodeRule codeRule) {

        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail( Integer id) {
//        CodeRule codeRule = codeRuleService.getOneByField("id", id);
        return null;//ResultGenerator.genSuccessResult(codeRule);
    }
}
